package stack;

import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;

/**
 * @Author : chenchao
 */
public class MyStack {

    public static void main(String[] args) throws IOException {
        Stack<Integer> stack = new Stack<Integer>();
        List<Integer> ret = new ArrayList<>();

        String path = "/home/chenchao/Nutstore Files/我的坚果云/020_架构/020-算法/010【周四】船长刷题直播课/003【第三周】递归与栈-0318/【第三周】递归与栈-彩蛋数据.txt";
        BufferedReader  fileReader = new BufferedReader( new FileReader(path));
        String line;
        while((line = fileReader.readLine()) != null){
            String[] arr = line.split(" ");
            if("push".equals(arr[0])){
                stack.push(Integer.valueOf(arr[1]));
            }else if("pop".equals(arr[0])){
                ret.add(stack.pop());
            }else {
                throw new RuntimeException("operation not support ... "+arr[0]);
            }
        }

        long retNum = 0;
        Iterator<Integer> it = ret.iterator();
        int i=0;
        while(it.hasNext()){
            i++;
            retNum += (i * it.next());
        }

        System.out.println("retNum:"+retNum);
    }
}
